package cn.edu.zhku.service.impl;

import cn.edu.zhku.dto.FormDto;
import cn.edu.zhku.pojo.form.*;
import cn.edu.zhku.service.AbstractState;
import org.springframework.stereotype.Component;

// 暂时保存
@Component("saveState")
public class SaveState extends AbstractState {

    private static final Integer state = 0;

    @Override
    public void doAction(FormDto formDto) {
        MainStem mainStem = formDto.getMainStem();
        FpolBranches fpolBranches = formDto.getFpolBranches();
        Branch branch = formDto.getBranch();
        Pods pods = formDto.getPods();
        Petiole baclPetiole = formDto.getBaclPetiole();
        Leaflet baclLeaflet = formDto.getBaclLeaflet();
        Petiole msclPetiole = formDto.getMsclPetiole();
        Leaflet msclLeaflet = formDto.getMsclLeaflet();
        Form form = formDto.getForm();
        form.setState(state);
        if (formDto.getFormId() == null) {
            PlantTraits plantTraits = formDto.getPlantTraits();
            SppTraits sppTraits = formDto.getSppTraits();
            BaclTraits baclTraits = formDto.getBaclTraits();
            MsclTraits msclTraits = formDto.getMsclTraits();
            Phenotype phenotype = formDto.getPhenotype();
            this.formService.addOne(form, phenotype, plantTraits, baclTraits,msclTraits,sppTraits,
                    mainStem, fpolBranches, branch, baclPetiole, baclLeaflet,
                    msclPetiole, msclLeaflet, pods);
        } else {
            this.formService.modifyOne(form, mainStem, fpolBranches, branch, pods,
                    baclPetiole, baclLeaflet, msclPetiole, msclLeaflet);
        }
    }

}
